//
// Created by yanhai on 2020/2/20.
//

#include <string>
#include "server/http_server.hpp"

/**
 * test:
 *  curl -X GET 'http://localhost:8000/v1/test?aa=%E4%B8%AD%E6%96%87%E6%B5%8B%E8%AF%95&bb=bb1&cc=cc1&cc=cc2&dd=dd1' --header 'Content-Type: application/x-www-form-urlencoded'
 * @param request
 * @param response
 * @param arg
 */
static void test(const Request *request, Response *response)
{
    std::string res;
    auto aa = request->uri.query().get("aa");
    auto bb = request->uri.query()["bb"];
    auto cc1 = request->uri.query()["cc"];
    auto cc = request->uri.query().getlist("cc");
    auto ee = request->uri.query().get("ee", "exx");

    res = "aa:";
    res += aa;
    res += "; bb:";
    res += bb;
    res += "; cc1:";
    res += cc1;
    res += "; cc:";
    for (auto &item: cc) {
        res += item + ",";
    }
    res += "; ee:";
    res += ee;

    response->write(res);
}

int main()
{
    auto &httpServer = HTTPServer::instance();
    httpServer.set_cb("/v1/test", test, EVHTTP_REQ_GET);
    httpServer.listen(8000, "0.0.0.0");
    httpServer.start();
    return 0;
}
